package test.springboot.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;

/**
 * @author lingkang
 * Created by 2024/3/10
 */
@RestController
public class WebController {
    @GetMapping("/")
    public Object index(HttpServletRequest request) {
        System.out.println(request.getRequestURI());
        System.out.println(request.getSession().getClass());
        return "ok";
    }

    @GetMapping("/session")
    public Object session(HttpServletRequest request) {
        HttpSession session = request.getSession();
        Object a = session.getAttribute("a");
        if (a == null) {
            session.setAttribute("a", System.currentTimeMillis());
        }
        System.out.println(a);
        return "ok";
    }
}
